# %cd /home/aistudio/output/train_data_zy
# 45	48	img_0.jpg	福
# 187	48	img_1.jpg	空调维修保养
# 192	48	img_2.jpg	空调移机保养

import os

root = 'D:/ocr/ocr_resouces/'

folders = ['街景']
# folders=['train_data_temp']

for folder in folders:
    contents = []
    with open(root + folder + '/train_demo.list', 'r', encoding='utf-8') as l:
        lines = l.readlines()
        # print(lines)
        for line in lines:
            print(line)
            splitIndex1 = line.find('\t')
            print(splitIndex1)
            splitIndex2 = line.find('\t', splitIndex1 + 1)
            print(splitIndex2)
            splitIndex3 = line.find('\t', splitIndex2 + 1)
            print(splitIndex3)
            fileName = line[splitIndex2 + 1:splitIndex3]
            fileContent = line[splitIndex3:len(line)].replace('\n', '').replace('\r', '').replace('\t', '')
            print(fileName)
            print(fileContent)
            content=root+folder+'/train_images/'+fileName+'\t'+fileContent+'\r\n'
            print(content)
            contents.append(content)
    with open(root + folder+".txt", 'wb') as target:
        target.truncate()
        for x in contents:
            target.write(x.encode('utf-8'))
